#pragma once

#include "Serializable.h"
#include "Events.h"

#include <string>
#include <ostream>
#include <vector>

class Team;
class ServiceProvider;

struct MatchTeamData
{
	std::vector<float>	m_teamStamina;
	std::vector<float>	m_teamAttackSkill;
	
	float				m_teamAttackSum;
	float				m_teamDefenseSum;
	float				m_gkSkill;
	
	Team*				m_team;
	size_t				m_goals;
};

class Match : public Serializable
{
public:

	static const float INJURY_THRESHOLD;

	explicit Match(ServiceProvider* i_sp);
	Match(ServiceProvider* i_sp, Team* const i_t1, Team* const i_t2);

	virtual	ZStream& Serialize(ZStream& o_stream);
	virtual ZStream& Deserialize(ZStream& i_stream);

	Team* GetTeam(size_t index) const;
	const size_t GetGoals(size_t index) const;
	const EventCollection& GetEvents() const;

	void Play(const bool i_produceEvents);

	const MatchTeamData& GetTeamData(const int i_num) const;

private:
	std::string		CurrentResult();
	void			TeamsCondition(size_t teamIndex);
	void			InitData();
	void			DecreaseStamina();
	void			CheckInMatchInjury();
	void			Shot(const size_t teamIndex, const bool i_produceEvents);
	void			PostMatchPlayerUpdate(const bool i_produceEvents);
	void			AppendEvent(const std::string& i_category, const std::string& i_name);

	ServiceProvider*	m_sp;
	EventCollection		m_events;
	MatchTeamData		m_data[2];

	int					m_minute;
};

inline Team* Match::GetTeam(size_t index) const
{
	return m_data[index].m_team;
}

inline const size_t Match::GetGoals(size_t index) const
{
	return m_data[index].m_goals;
}

inline const EventCollection& Match::GetEvents() const
{
	return m_events;
}

inline const MatchTeamData& Match::GetTeamData(const int i_num) const
{
	return m_data[i_num];
}
